package com.shop2cn.iapi.coupon.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.coupon.parameter.ReturnCouponBean;
import com.shop2cn.iapi.coupon.parameter.UseCouponBean;
import com.shop2cn.iapi.coupon.service.ReturnCouponCall;
import com.shop2cn.iapi.coupon.service.UserReceiveCouponCall;
import com.shop2cn.iapi.couponmanage.parameter.CreateCouponBean;
import com.shop2cn.iapi.couponmanage.parameter.SellerCreateBatchBean;
import com.shop2cn.iapi.couponmanage.service.CreateCouponCall;
import com.shop2cn.iapi.couponmanage.service.SellerCreateBatchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponShop2cnCallService;
import com.ymttest.business.service.CouponShop2cnMCallService;
import com.ymttest.database.model.CouponShop2cn.coupon;
import com.ymttest.database.model.CouponShop2cn.couponbatch;
import com.ymttest.database.sqlwapper.CouponShop2cn.couponWapper;
import com.ymttest.database.sqlwapper.CouponShop2cn.couponbatchWapper;
import com.ymttest.utils.TestDataManager;
/**
*还券
*FreeMaker Template自动生成代码
*<!--添加还券记录-->
		insert into ymt_CouponTradeRecord (OrderId, UserId, CouponCode, BatchId, TradeType)
		values (#{orderId,jdbcType=INTEGER},
		#{userId,jdbcType=INTEGER},
		#{couponCode,jdbcType=VARCHAR},
		#{batchId,jdbcType=INTEGER},
		#{tradeType,jdbcType=TINYINT})

		<!--增加用户优惠券使用剩余次数-->
		UPDATE a SET iCouponUsedCount=iCouponUsedCount+1 from Ymt_CouponPrivateUserBound a with (index  = IX_Ymt_CouponPrivateUserBound_sCouponCode)
		WHERE sCouponCode=#{couponCode, jdbcType=VARCHAR}
		AND iUserId=#{userId, jdbcType=INTEGER}

		<!--更新批次优惠券剩余使用次数-->
		UPDATE Ymt_CouponSetting SET iMaxUseTime=iMaxUseTime+1
		WHERE iCouponSettingId IN (SELECT iCouponSettingId FROM Ymt_CouponBatch WITH(NOLOCK) WHERE ibatchid=#{batchId, jdbcType=INTEGER})
*/
@TestSuite
public class Ts_ReturnCoupon{ 
	private static ReturnCouponBean returncouponBean;
	private static ReturnCouponCall returncouponCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("还券");
	}

	@Before
	public void caseUp() {
		returncouponBean=new ReturnCouponBean();
		returncouponCall=new ReturnCouponCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(returncouponCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnCoupon_001() {
		Logger.start(true,"还券-平台券-领取券");
		try {
			
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			CreateCouponBean createCouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall= CouponShop2cnMCallService.createPlatformCoupon(createCouponBean);
			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			String couponCode = userReceiveCouponCall.getUserReceiveResult().getCouponCode();
			couponbatch batch1 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			UseCouponBean useCouponBean = CouponShop2cnCallService.setUseCouponBean(userId, orderId, couponCode);
			CouponShop2cnCallService.useCoupon(useCouponBean);
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			couponbatch batch2 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			List<String> CouponCodes=new ArrayList();
			CouponCodes.add(couponCode);
			returncouponBean.setUserId(userId);
			returncouponBean.setMainOrderId(orderId);
			returncouponBean.setCouponCodes(CouponCodes);
			returncouponBean.setAppId("app");
			returncouponBean.setRequestId("1233344");			
			
			returncouponCall.setData(returncouponBean);
			returncouponCall.callService();		
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			couponbatch batch3 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			//还券前已使用和接收数量
			Logger.verifyEquals(1, batch2.getUsedCount()-batch1.getUsedCount(), "验证还券前数据库couponbatch中UsedCount");
			Logger.verifyEquals(0, batch1.getReceivedCount()-batch2.getReceivedCount(), "验证还券前数据库couponbatch中ReceivedCount");
			//还券后已使用和接收数量
			Logger.verifyEquals(1, batch2.getUsedCount()-batch3.getUsedCount(), "验证还券后数据库couponbatch中UsedCount");
			Logger.verifyEquals(0, batch2.getReceivedCount()-batch3.getReceivedCount(), "验证还券后数据库couponbatch中ReceivedCount");
			
			coupon coupon=new couponWapper().selectByBatchId(batch1.getBatchId()).get(0);
			Logger.verifyEquals(false, coupon.getIsUsed(), "验证数据库coupon中IsUsed");
			Logger.verifyEquals(returncouponBean.getMainOrderId(), coupon.getMainOrderId(), "验证数据库coupon中MainOrderId");
			
			Logger.verifyEquals("操作成功！", returncouponCall.getMessage(), "验证返回Message");
			Logger.verifyEquals("0", returncouponCall.getStatusCode1(), "验证返回StatusCode");

			Logger.verifyEquals("null", returncouponCall.getSellerId(), "验证返回sellerId");		
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnCoupon_002() {
		Logger.start(true,"还券-商家券");
		try {
			
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			SellerCreateBatchBean sellerCreateBatchBean = CouponShop2cnMCallService.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall createCouponCall= CouponShop2cnMCallService.SellerCreateBatch(sellerCreateBatchBean);
			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			
			String couponCode = userReceiveCouponCall.getUserReceiveResult().getCouponCode();
			
            couponbatch batch1 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			UseCouponBean useCouponBean = CouponShop2cnCallService.setUseCouponBean(userId, orderId, couponCode);
			CouponShop2cnCallService.useCoupon(useCouponBean);
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			couponbatch batch2 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			List<String> CouponCodes=new ArrayList();
			CouponCodes.add(couponCode);
			returncouponBean.setUserId(userId);
			returncouponBean.setMainOrderId(orderId);
			returncouponBean.setCouponCodes(CouponCodes);
			returncouponBean.setAppId("app");
			returncouponBean.setRequestId("1233344");			
			
			returncouponCall.setData(returncouponBean);
			returncouponCall.callService();		
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			couponbatch batch3 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			//还券前已使用和接收数量
			Logger.verifyEquals(1, batch2.getUsedCount()-batch1.getUsedCount(), "验证还券前数据库couponbatch中UsedCount");
			Logger.verifyEquals(0, batch1.getReceivedCount()-batch2.getReceivedCount(), "验证还券前数据库couponbatch中ReceivedCount");
			//还券后已使用和接收数量
			Logger.verifyEquals(1, batch2.getUsedCount()-batch3.getUsedCount(), "验证还券后数据库couponbatch中UsedCount");
			Logger.verifyEquals(0, batch2.getReceivedCount()-batch3.getReceivedCount(), "验证还券后数据库couponbatch中ReceivedCount");
			
			coupon coupon=new couponWapper().selectByBatchId(batch1.getBatchId()).get(0);
			Logger.verifyEquals(false, coupon.getIsUsed(), "验证数据库coupon中IsUsed");
			Logger.verifyEquals(returncouponBean.getMainOrderId(), coupon.getMainOrderId(), "验证数据库coupon中MainOrderId");
			
			Logger.verifyEquals("操作成功！", returncouponCall.getMessage(), "验证返回Message");
			Logger.verifyEquals("0", returncouponCall.getStatusCode1(), "验证返回StatusCode");

			Logger.verifyEquals("null", returncouponCall.getSellerId(), "验证返回sellerId");		
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnCoupon_003() {
		Logger.start(true,"还券-OrderId空");
		try {
			
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			CreateCouponBean createCouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall= CouponShop2cnMCallService.createPlatformCoupon(createCouponBean);
			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			String couponCode = userReceiveCouponCall.getUserReceiveResult().getCouponCode();
			
		   couponbatch batch1 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			UseCouponBean useCouponBean = CouponShop2cnCallService.setUseCouponBean(userId, orderId, couponCode);
			CouponShop2cnCallService.useCoupon(useCouponBean);
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			couponbatch batch2 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			List<String> CouponCodes=new ArrayList();
			CouponCodes.add(couponCode);
			returncouponBean.setUserId(userId);
			returncouponBean.setCouponCodes(CouponCodes);
			returncouponBean.setAppId("app");
			returncouponBean.setRequestId("1233344");			
			
			returncouponCall.setData(returncouponBean);
			returncouponCall.callService();		
			
			couponbatch batch3 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			coupon coupon=new couponWapper().selectByBatchId(batch1.getBatchId()).get(0);
			Logger.verifyEquals(true, coupon.getIsUsed(), "验证数据库coupon中IsUsed");
			Logger.verifyEquals(true, returncouponCall.getMessage().contains("mainOrderId must"), "验证返回Message");
			Logger.verifyEquals("1", returncouponCall.getStatusCode1(), "验证返回StatusCode");
			
			//还券前已使用和接收数量
			Logger.verifyEquals(1, batch2.getUsedCount()-batch1.getUsedCount(), "验证还券前数据库couponbatch中UsedCount");
			Logger.verifyEquals(0, batch1.getReceivedCount()-batch2.getReceivedCount(), "验证还券前数据库couponbatch中ReceivedCount");
			//还券后已使用和接收数量
			Logger.verifyEquals(0, batch2.getUsedCount()-batch3.getUsedCount(), "验证还券后数据库couponbatch中UsedCount");
			Logger.verifyEquals(0, batch2.getReceivedCount()-batch3.getReceivedCount(), "验证还券后数据库couponbatch中ReceivedCount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnCoupon_004() {
		Logger.start(true,"还券-CouponCode空");
		try {
			
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			CreateCouponBean createCouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall= CouponShop2cnMCallService.createPlatformCoupon(createCouponBean);
			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			String couponCode = userReceiveCouponCall.getUserReceiveResult().getCouponCode();
		   couponbatch batch1 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			UseCouponBean useCouponBean = CouponShop2cnCallService.setUseCouponBean(userId, orderId, couponCode);
			CouponShop2cnCallService.useCoupon(useCouponBean);
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			couponbatch batch2 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			List<String> CouponCodes=new ArrayList();
			returncouponBean.setUserId(userId);
			returncouponBean.setMainOrderId(orderId);
			returncouponBean.setCouponCodes(CouponCodes);
			returncouponBean.setAppId("app");
			returncouponBean.setRequestId("1233344");				
			
			returncouponCall.setData(returncouponBean);
			returncouponCall.callService();		
			
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			couponbatch batch3 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			coupon coupon=new couponWapper().selectByBatchId(batch1.getBatchId()).get(0);
			Logger.verifyEquals(true, coupon.getIsUsed(), "验证数据库coupon中IsUsed");
			Logger.verifyEquals(true, returncouponCall.getMessage().contains("couponCodes:couponcodes must"), "验证返回Message");
			Logger.verifyEquals("1", returncouponCall.getStatusCode1(), "验证返回StatusCode");
			
			//还券前已使用和接收数量
			Logger.verifyEquals(1, batch2.getUsedCount()-batch1.getUsedCount(), "验证还券前数据库couponbatch中UsedCount");
			Logger.verifyEquals(0, batch1.getReceivedCount()-batch2.getReceivedCount(), "验证还券前数据库couponbatch中ReceivedCount");
			//还券后已使用和接收数量
			Logger.verifyEquals(0, batch2.getUsedCount()-batch3.getUsedCount(), "验证还券后数据库couponbatch中UsedCount");
			Logger.verifyEquals(0, batch2.getReceivedCount()-batch3.getReceivedCount(), "验证还券后数据库couponbatch中ReceivedCount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnCoupon_006() {
		Logger.start(true,"还券-userId空");
		try {
			
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			CreateCouponBean createCouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall= CouponShop2cnMCallService.createPlatformCoupon(createCouponBean);
			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			String couponCode = userReceiveCouponCall.getUserReceiveResult().getCouponCode();
			
		   couponbatch batch1 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			UseCouponBean useCouponBean = CouponShop2cnCallService.setUseCouponBean(userId, orderId, couponCode);
			CouponShop2cnCallService.useCoupon(useCouponBean);
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			couponbatch batch2 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			List<String> CouponCodes=new ArrayList();
			CouponCodes.add(couponCode);
			//returncouponBean.setUserId(userId);
			returncouponBean.setMainOrderId(orderId);
			returncouponBean.setCouponCodes(CouponCodes);
			returncouponBean.setAppId("app");
			returncouponBean.setRequestId("1233344");				
			
			returncouponCall.setData(returncouponBean);
			returncouponCall.callService();		
			
			couponbatch batch3 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			coupon coupon=new couponWapper().selectByBatchId(batch1.getBatchId()).get(0);
			Logger.verifyEquals(true, coupon.getIsUsed(), "验证数据库coupon中IsUsed");
			Logger.verifyEquals(true, returncouponCall.getMessage().contains("userId must"), "验证返回Message");
			Logger.verifyEquals("1", returncouponCall.getStatusCode1(), "验证返回StatusCode");
			
			//还券前已使用和接收数量
			Logger.verifyEquals(1, batch2.getUsedCount()-batch1.getUsedCount(), "验证还券前数据库couponbatch中UsedCount");
			Logger.verifyEquals(0, batch1.getReceivedCount()-batch2.getReceivedCount(), "验证还券前数据库couponbatch中ReceivedCount");
			//还券后已使用和接收数量
			Logger.verifyEquals(0, batch2.getUsedCount()-batch3.getUsedCount(), "验证还券后数据库couponbatch中UsedCount");
			Logger.verifyEquals(0, batch2.getReceivedCount()-batch3.getReceivedCount(), "验证还券后数据库couponbatch中ReceivedCount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnCoupon_005() {
		Logger.start(true,"还券-用户优惠券不存在");
		try {
			
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			CreateCouponBean createCouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall= CouponShop2cnMCallService.createPlatformCoupon(createCouponBean);
			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			String couponCode = userReceiveCouponCall.getUserReceiveResult().getCouponCode();
			
		   couponbatch batch1 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			UseCouponBean useCouponBean = CouponShop2cnCallService.setUseCouponBean(userId, orderId, couponCode);
			CouponShop2cnCallService.useCoupon(useCouponBean);
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			couponbatch batch2 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			List<String> CouponCodes=new ArrayList();
			CouponCodes.add(couponCode);
			returncouponBean.setUserId(1);
			returncouponBean.setMainOrderId(orderId);
			returncouponBean.setCouponCodes(CouponCodes);

			returncouponBean.setAppId("app");
			returncouponBean.setRequestId("1233344");				
			
			returncouponCall.setData(returncouponBean);
			returncouponCall.callService();		
			
			couponbatch batch3 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			coupon coupon=new couponWapper().selectByBatchId(batch1.getBatchId()).get(0);
			Logger.verifyEquals(true, coupon.getIsUsed(), "验证数据库coupon中IsUsed");			
//			Logger.verifyEquals(true, returncouponCall.getMessage().contains("未找到符合条件的用户优惠券|优惠券不属于当前用户"), "验证返回Message");
//			Logger.verifyEquals("21002", returncouponCall.getStatusCode1(), "验证返回StatusCode");
			
			//研发修改：返券都返回成功，目的为了消息总线不再回调
			Logger.verifyEquals(true, returncouponCall.getMessage().contains("操作成功"), "验证返回Message");
			Logger.verifyEquals("0", returncouponCall.getStatusCode1(), "验证返回StatusCode");
			
			//还券前已使用和接收数量
			Logger.verifyEquals(1, batch2.getUsedCount()-batch1.getUsedCount(), "验证还券前数据库couponbatch中UsedCount");
			Logger.verifyEquals(0, batch1.getReceivedCount()-batch2.getReceivedCount(), "验证还券前数据库couponbatch中ReceivedCount");
			//还券后已使用和接收数量
			Logger.verifyEquals(0, batch2.getUsedCount()-batch3.getUsedCount(), "验证还券后数据库couponbatch中UsedCount");
			Logger.verifyEquals(0, batch2.getReceivedCount()-batch3.getReceivedCount(), "验证还券后数据库couponbatch中ReceivedCount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnCoupon_009() {
		Logger.start(true,"还券-优惠券不存在");
		try {
			
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			CreateCouponBean createCouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall= CouponShop2cnMCallService.createPlatformCoupon(createCouponBean);
			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			String couponCode = userReceiveCouponCall.getUserReceiveResult().getCouponCode();
			
		   couponbatch batch1 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			UseCouponBean useCouponBean = CouponShop2cnCallService.setUseCouponBean(userId, orderId, couponCode);
			CouponShop2cnCallService.useCoupon(useCouponBean);
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			couponbatch batch2 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			List<String> CouponCodes=new ArrayList();
			CouponCodes.add(couponCode+11);
			returncouponBean.setUserId(userId);
			returncouponBean.setMainOrderId(orderId);
			returncouponBean.setCouponCodes(CouponCodes);

			returncouponBean.setAppId("app");
			returncouponBean.setRequestId("1233344");				
			
			returncouponCall.setData(returncouponBean);
			returncouponCall.callService();		
			
		
			Logger.verifyEquals("操作成功！", returncouponCall.getMessage(), "验证返回Message");
			Logger.verifyEquals("0", returncouponCall.getStatusCode1(), "验证返回StatusCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnCoupon_008() {
		Logger.start(true,"还券-OrderId与CouponCode不匹配");
		try {
			
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			CreateCouponBean createCouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall= CouponShop2cnMCallService.createPlatformCoupon(createCouponBean);
			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			String couponCode = userReceiveCouponCall.getUserReceiveResult().getCouponCode();
			
		   couponbatch batch1 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			UseCouponBean useCouponBean = CouponShop2cnCallService.setUseCouponBean(userId, orderId, couponCode);
			CouponShop2cnCallService.useCoupon(useCouponBean);
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponShop2cnMCallService().updatereceivedandusedcount();
			
			couponbatch batch2 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			
			List<String> CouponCodes=new ArrayList();
			CouponCodes.add(couponCode);
			returncouponBean.setUserId(userId);
			returncouponBean.setMainOrderId(orderId+1);
			returncouponBean.setCouponCodes(CouponCodes);

			returncouponBean.setAppId("app");
			returncouponBean.setRequestId("1233344");				
			
			returncouponCall.setData(returncouponBean);
			returncouponCall.callService();		
			
			couponbatch batch3 = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
			coupon coupon=new couponWapper().selectByBatchId(batch1.getBatchId()).get(0);
			Logger.verifyEquals(true, coupon.getIsUsed(), "验证数据库coupon中IsUsed");
			//研发修改：返券都返回成功，目的为了消息总线不再回调
			Logger.verifyEquals(true, returncouponCall.getMessage().contains("操作成功"), "验证返回Message");
			Logger.verifyEquals("0", returncouponCall.getStatusCode1(), "验证返回StatusCode");
			
//			Logger.verifyEquals(true, returncouponCall.getMessage().contains("优惠券已使用，但不是用在此主订单号上"), "验证返回Message");
//			Logger.verifyEquals("21003", returncouponCall.getStatusCode1(), "验证返回StatusCode");
			
			//还券前已使用和接收数量
			Logger.verifyEquals(1, batch2.getUsedCount()-batch1.getUsedCount(), "验证还券前数据库couponbatch中UsedCount");
			Logger.verifyEquals(0, batch1.getReceivedCount()-batch2.getReceivedCount(), "验证还券前数据库couponbatch中ReceivedCount");
			//还券后已使用和接收数量
			Logger.verifyEquals(0, batch2.getUsedCount()-batch3.getUsedCount(), "验证还券后数据库couponbatch中UsedCount");
			Logger.verifyEquals(0, batch2.getReceivedCount()-batch3.getReceivedCount(), "验证还券后数据库couponbatch中ReceivedCount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}